<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Session;
use DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\validator;
use Illuminate\Support\Facades\Storage;
class CommonController extends Controller{
    public function __construct(){
        if(!Session::get('u_name')){
            header("Location:login");die;
        }  
        if(!isset($_SERVER["HTTP_REFERER"])){
            echo "<script>alert('非法操作!');history.back();</script>";die;
        }
    }
    public function getCurrentMethodName()
    {
        $action = \Route::current()->getActionName();
        list($class, $method) = explode('@', $action);
        $class = substr(strrchr($class,'\\'),1);
        return ['controller' => $class, 'method' => $method];
    }
    public function power(){
        $role_id = session('role_id');
        $node_id = session('r_id');
        $huiyuan_id = DB::table('mo_node')->select('id')->where(["n_id" =>$node_id,'n_name'=>'会员管理'])->first();
        //var_dump($huiyuan_id);die;
        $h_id = $huiyuan_id->id;
        $row = DB::table('mo_access')->select('sq_id')->where(["role_id" =>$node_id,'node_id'=>$h_id])->get();
        //var_dump($row);die;
        if($row == ""){
            return false;die;
        }else{
            foreach($row as $k=>$v){
                @$data[] = $v->sq_id;
            }
            $array = DB::table('mo_sql')->select('title')->whereIn("sq_id" ,@$data)->get();
            foreach($array as $k=>$v){
                $sel[] = $v->title;
            }
            return @$sel;
        }
    }
    public function ifright(){
        //var_dump(session('r_id'));die;
            $res= $this->getCurrentMethodName();
            $method = $res['method'];
            $sel = $this->power();
            if($sel == '' || @!in_array($method,$sel)){
                return "no";die;
            }
    }
}